package ay.shadow.core.utils;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * @author shadow
 */
public class Md5Util {
    public static String md5(String str){
        return DigestUtils.md5Hex(str);
    }
    private static final String salt="shadow2323";

    public static String inputPassToFromPass(String inputPass){
       return md5(""+salt.charAt(0)+salt.charAt(2)+inputPass);
    }

    public static String formToPass(String formPass,String salt){
        return md5(""+salt.charAt(0)+salt.charAt(2)+formPass+salt);
    }

    public static String inputPassToDbPass(String inputPass,String salt){
        String fromPass = inputPassToFromPass(inputPass);
        return formToPass(fromPass, salt);
    }

    public static void main(String[] args) {
        //58d65bdd8944dc8375c30b2ba10ae699
        String s = inputPassToFromPass("123456");
        String s1 = formToPass("58d65bdd8944dc8375c30b2ba10ae699","shadow2323");
        String s2 = inputPassToDbPass("123456","shadow2323");
        System.out.println(s);
        System.out.println(s1);
        System.out.println(s2);
    }
}
